const memFs = require('mem-fs');
const memFsEditor = require('mem-fs-editor');
const path = require('path');


class FsHelper {
  constructor(base) {
    const store = memFs.create()
    this._mfs = memFsEditor.create(store);
    this._base = base
    console.info('base:', base)
  }

  getTplPath(file) {
    return path.join(this._base, file)
  }

  copyTpl(file, to, data) {
    const filePath = this.getTplPath(file);
    console.log(file, to);
    this._mfs.copyTpl(filePath, to, data);
  }
  copyTplSameDirectory(file, to, data) {
    const filePath = this.getTplPath(file);
    const toPath = this.getTplPath(to);
    this._mfs.copyTpl(filePath, toPath, data);
  }

  resetTpl(file, data) {
    const filePath = this.getTplPath(file);
    console.log(filePath);
    this._mfs.copyTpl(filePath, filePath, data);
  }

  commit(callback = () => void 0) {
    this._mfs.commit(callback);
  }
}

module.exports = FsHelper;

// let p = path.resolve(__dirname, '..', 'template')
// console.log(p);
// let p = path.resolve(process.cwd(), 'template', 'a.json')
// console.log(p);

// let p = path.join(process.cwd(), '/file', '\file')
// console.log(p);

// let p = path.format({
//   dir: process.cwd(),
//   name: 'template',
//   base: 'ss'
// })
// console.log(p);

